<template>
  <div>
    <h2>08 - mock.js</h2>
    <h3>生成随机数据</h3>
    <button @click="getData">使用 mock 生成数据</button>
    <h3>拦截 ajax 请求</h3>
    <button @click="getServeData">拦截 ajax 请求</button>
  </div>
</template>

<script>
// 导入 mock
import Mock from 'mockjs'
// 导入 axios
import axios from 'axios'
export default {
  data () {
    return {}
  },
  methods: {
    // 生成随机数据
    getData () {
      console.log('生成随机数据')
      // { list: [{id: 1}, {id: 2}, {id: 3}, {id:4}] }
      var data = Mock.mock({
        'list|1-10': [
          {
            'id|+1': 1,
            first: '@cFIRST',
            last: '@cLAST',
            fullname: '@first @last'
          }
        ]
      })
      console.log(data)
    },
    // 拦截 ajax 请求
    async getServeData () {
      const res = await axios({
        url: '/getServerData',
        method: 'GET'
      })
      console.log(res.data)
    }
  }
}
</script>

<style></style>
